package com.shopping.orm;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class LinkDao extends HibernateDaoSupport {

	private static final Log log = LogFactory.getLog(LinkDao.class);
	public void save(Commodity instance){
		log.debug("saving Link instance");
		try{
		getHibernateTemplate().save(instance);
		log.debug("save Link successful");
		}catch(RuntimeException re){
			log.error("save Link failed",re);
			throw re;
		}
	}
	
	public void delete(Link instance) {
        log.debug("deleting Link instance");
        try {
            getHibernateTemplate().delete(instance);
            log.debug("delete Link instance successful");
        } catch (RuntimeException re) {
            log.error("delete Link instance failed", re);
            throw re;
        }
    }
	
	public void update(Link instance){
		log.debug("Upate Link instance");
		try{
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("update Link instance  successful");
			
		}catch(RuntimeException re){
			log.error("update Link instance failed",re);
			throw re;
		}
	}
	public List findByExample(Link instance){
		log.debug("get Link instance with +:example");
		try{
			List result = getHibernateTemplate().findByExample(instance);
			log.debug("get successful!");
			return result;
		}catch(RuntimeException re){
			log.error("get failed",re);
			throw re;
		}
	}
	
	public List findByproperty(String propertyName,Object value){
		log.debug("finding Link instance with property:"+ propertyName + ",value:"+value);
		try {
		    String queryString = "from Link as model where model." 
		         						+ propertyName + "= ?";
		    queryString = queryString + "order by adddate";
		    return getHibernateTemplate().find(queryString, value);
		}catch(RuntimeException re){
			log.error("find by property failed",re);
			throw re;
		}
	}
	
	
	
	public List findAll(){
		log.debug("getting Link instance");		
		try{
			List result = getHibernateTemplate().find("from Link");
			log.debug("find successful!");
			return result;
		}catch(RuntimeException re){
			log.error("get failed",re);
			throw re;
		}
	}
	
	
	public Link findById(String uid){
		log.debug("get Link instance with id:+uid");
		try{
			Link instance = (Link)getHibernateTemplate().get("Link", uid);
			log.debug("get successful!");
			return instance;
		}catch(RuntimeException re){
			log.error("get failed",re);
			throw re;
		}	
	}
}
